<template>
  <div style="padding: 20px">
    <div class="title_font">
      添加产品
    </div>
    <el-divider />

    <div style="display: flex;justify-content: left">
      <div class="item_font" style="margin-right: 20px">产品图标：</div>
      <el-upload
          class="avatar-uploader"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
      </el-upload>
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">产品名称：</div>
      <el-input v-model="input" placeholder="请输入" class="input_style" />
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">最高贷款额度：</div>
      <el-input v-model="input" placeholder="请输入" class="input_style"/>
      <div class="right_style">元</div>
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">年利率：</div>
      <el-input v-model="input" placeholder="请输入" class="input_style" style="width: 100px"/>
      <span style="margin-left: 20px;margin-top: 10px">-</span>
      <el-input v-model="input" placeholder="请输入" class="input_style" style="width: 100px"/>
      <div class="right_style">%</div>
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">贷款期限：</div>
      <el-input v-model="input" placeholder="请输入" class="input_style" style="width: 100px"/>
      <span style="margin-left: 20px;margin-top: 10px">-</span>
      <el-input v-model="input" placeholder="请输入" class="input_style" style="width: 100px"/>
      <div class="right_style">月</div>
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">产品类型：</div>
      <el-select v-model="value_2" placeholder="请选择" class="input_style" style="width: 150px;height: 30px" >
        <el-option v-for="item in startlist" :key="item.value" :label="item.label" :value="item.value" ></el-option>
      </el-select>
    </div>
    <div>
      <div style="display: flex;justify-content: left">
        <div class="item_font">产品标签：</div>
        <el-tag size="small" style="margin-top: 10px;margin-left: 20px">School</el-tag>
      </div>
      <div style="display: flex;justify-content: left">
        <el-input v-model="input" placeholder="请输入" class="input_style" style="width: 150px;margin-left: 170px"/>
        <button class="input_button">+添加</button>
      </div>
    </div>
    <div style="display: flex;justify-content: left">
      <div class="item_font">产品介绍：</div>
      <el-input v-model="input"  type="textarea" placeholder="输入产品介绍" class="input_style" />
    </div>

  </div>
  <el-divider style="width: 90%;margin: auto;margin-top: 20px"/>
  <div class="button_styles">
    <button class="add_button">添加</button>
    <button class="chance_button">取消</button>
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import type { UploadProps } from 'element-plus'
const imageUrl = ref('')
const handleAvatarSuccess: UploadProps['onSuccess'] = (
    response,
    uploadFile
) => {
  imageUrl.value = URL.createObjectURL(uploadFile.raw!)
}

const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
  if (rawFile.type !== 'image/jpeg') {
    ElMessage.error('Avatar picture must be JPG format!')
    return false
  } else if (rawFile.size / 1024 / 1024 > 2) {
    ElMessage.error('Avatar picture size can not exceed 2MB!')
    return false
  }
  return true
}
</script>
<style lang="scss">
.button_styles{
  margin-left: 80px;
  margin-top: 20px;
  .add_button{
    width: 100px;
    background-color: #165dff;
    color: white;
    font-weight: 500;
    border: 0;
    height: 30px;
    border-radius: 3px;
  }
  .chance_button{
    margin-left: 20px;
    width: 100px;
    background-color: white;
    font-weight: 500;
    border: 1px solid black;
    height: 30px;
    border-radius: 3px;
  }
}
.input_button{
  width: 60px;
  height: 30px;
  margin-top: 10px;
  color: white;
  background-color: #165dff;
  border: 0;
  border-radius: 3px;
  margin-left: 10px;
  font-weight: 500;
  font-size: 12px
}
.right_style{
  text-align: right;
  margin-top: 14px;
  margin-left: 8px;
  color: rgb(145,145,145);
  font-size: 12px;
}
.input_style{
  margin-top: 8px;
  height: 30px;
  width: 300px;
  margin-left: 20px;
}
.item_font{
  width: 100px;
  text-align: right;
  margin-top: 12px;
  margin-left: 50px;
  font-size: 12px;
}
.title_font{
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
}
</style>

<style scoped>
.avatar-uploader .avatar {
  width: 40px;
  height: 40px;
  display: block;
}
</style>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 60px;
  height: 60px;
  text-align: center;
}
</style>
